// pages/mySelf/Index/index.js
const common = require('../../../public.js')
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        userInfo: null,
        nianList:{}
    },
    /**
     * 生命周期函数--监听页面加载
     */
      /**
   * 跳转页面，该接口会验证用户是否登录
   * @param {string} url 跳转连接
   * "pages/cardLists/index",
   */
  // 点击申请入驻
  applyEnter() { 
    common.showToast('请登录飞羊精选app查看')
  },
  //联系客服
  contactServer() { 
    wx.navigateTo({
      url: '/packageB/pages/custService/index',
    })
  },
  GO_nian(){
    wx.navigateTo({
      url: '/pages/cardLists/index',
    })
  },
  checkLoginToJump(url) {
    if (!this.data.userInfo) {
      common.showToast('您尚未登录，请登录后再查看吧~')
    } else {
      wx.navigateTo({
        url
      })
    }
  },
    onChange(event) {
        // event.detail 的值为当前选中项的索引
        this.setData({ active: event.detail });
        if(this.data.active==0){
          var  url="/packageA/pages/indexnian/indexni?act=" + this.data.active
        }else {
          var  url="/pages/myNSelf/Index/index?act=" + this.data.active
        }
        wx.navigateTo({
          url: url,
        })
      },
      // 收货地址
    toAddressManager() {
      this.checkLoginToJump('/packageA/pages/Goods/Address/list/index?from=mySelf')
    },
    // 跳转我的会员卡 
    click_myCard(){
        wx.navigateTo({
            url:'/pages/myNian/myNian'      
        })
    },
      // 跳转会员卡订单
  toNianOrder(){
    wx.navigateTo({
      url: '/pages/ScenicArea/NianCardOrder/index',
    })
  },
    // 预约
    click_quan(e){
      var id = e.currentTarget.dataset.id
      if(id ==1){ //全部
         var url ='/pages/ScenicArea/NianCardOrder/index?status=' + ''
      }else if(id ==2){ //未支付
        var url ='/pages/ScenicArea/NianCardOrder/index?status=' + '2'
      }else if(id ==3){ //已支付
        var url ='/pages/ScenicArea/NianCardOrder/index?status=' + '3'
      }else if(id ==5){ //已完成
        var url ='/pages/ScenicArea/NianCardOrder/index?status=' + '5'
      }
      // var url = '/pages/ScenicArea/NianCardOrder/index'
      wx.navigateTo({
        url: url,
      })
    },
    Yu(){
    var that = this
    common.get('/userAnnualCard/getMyReserve', { 
     userId:that.data.userInfo.id,
     token:that.data.token
    }, res => {  
      that.setData({
        nianList:res.data
       })
    })
    },
    onLoad: function (options) {
     if(options.act){
        this.setData({
          active:parseInt(options.act)
        })
      }
      const that = this
      common.getLocalUserInfo(function (success, data) {
        if (success) {
          that.setData({
            userInfo: data.user,
            token: data.token
          }, function () {
            console.log(data.user,"33333")
            that.Yu()
          })
        } else {
          that.setData({
            userInfo: null,
            token: '',
          })
        }
      })
    
    },
})